home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / NB.ASM < prev    next >
Assembly Source File  |  1991-02-08  |  13KB  |  506 lines

  1. version equ     3
  2.  
  3.         include defs.asm        ;SEE ENCLOSED COPYRIGHT MESSAGE
  4. NCB_NOWAIT         equ 80h         ;  Command wait flag
  5.  
  6. NCB_RESET          equ 32h         ;  Reset adapter
  7. NCB_CANCEL         equ 35h         ;  Cancel command
  8. NCB_STATUS         equ 33h         ;  Get NETBIOS intf status
  9. NCB_UNLINK         equ 70h         ;  Unlink   (RPL)
  10. NCB_ADDNAME        equ 30h         ;  Add name
  11. NCB_ADDGNAME       equ 36h         ;  Add group name
  12. NCB_DELNAME        equ 31h         ;  Delete name
  13. NCB_FINDNAME       equ 78h         ;  Find name
  14. NCB_CALL           equ 10h         ;  Call
  15. NCB_LISTEN         equ 11h         ;  Listen
  16. NCB_HANGUP         equ 12h         ;  Hang up
  17. NCB_SEND           equ 14h         ;  Send
  18. NCB_CHSEND         equ 17h         ;  Chain send
  19. NCB_RECEIVE        equ 15h         ;  Receive
  20. NCB_RECANY         equ 16h         ;  Receive any
  21. NCB_SESSTATUS      equ 34h         ;  Get session status
  22. NCB_SDATAGRAM      equ 20h         ;  Send datagram
  23. NCB_SBROADCAST     equ 22h         ;  Send broadcast
  24. NCB_RDATAGRAM      equ 21h         ;  Receive datagram
  25. NCB_RBROADCAST     equ 23h         ;  Receive broadcast
  26. NCB_TRACE          equ 79h         ;  Start trace
  27.  
  28. ncb             struc
  29. ncb_command     db ?
  30. ncb_retcode     db ?
  31. ncb_lsn         db ?
  32. ncb_num         db ?
  33. ncb_buffer      dd ?
  34. ncb_length      dw ?
  35. ncb_callname    db 16 dup(?)
  36. ncb_name        db 16 dup(?)
  37. ncb_rto         db ?
  38. ncb_sto         db ?
  39. ncb_post        dd ?
  40. ncb_lana_num    db ?
  41. ncb_cmd_cplt    db ?
  42. ncb_reserve     db 14 dup(?)
  43. ncb             ends
  44.  
  45. code    segment word public
  46.         assume  cs:code, ds:code
  47. ;***************************************************************
  48. prefix          db "TCPIP"
  49.  
  50.         public  int_no
  51. int_no  db      0,0,0,0
  52. ip_adress       dw      2 dup(0)
  53. rq_size         dw      3
  54. padding         dd      0
  55.  
  56.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  57. driver_class    db      6,0             ;from the packet spec
  58. driver_type     db      0               ;from the packet spec
  59. driver_name     db      'netbios',0     ;name of the driver.
  60. driver_function    db    2
  61. parameter_list    label    byte
  62.     db    1    ;major rev of packet driver
  63.     db    9    ;minor rev of packet driver
  64.     db    14    ;length of parameter list
  65.     db    EADDR_LEN    ;length of MAC-layer address
  66.     dw    512    ;MTU, including MAC headers
  67.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  68.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  69.     dw    0    ;(# of successive xmits) - 1
  70. int_num    dw    0    ;Interrupt # to hook for post-EOI
  71.             ;processing, 0 == none,
  72.  
  73.     public    rcv_modes
  74. rcv_modes    dw    4        ;number of receive modes in our table.
  75.         dw    0,0,0,rcv_mode_3
  76.  
  77. lana_num        db 0
  78. local_ncb_num   db 0  ; handle returned by add_name
  79.  
  80.  
  81.         public  nbsend, nbrcv1, nbrcv2, rcv_buffer1, rcv_buffer2 ; MAP
  82. nbsend          ncb <>
  83. nbrcv1          ncb <>
  84. nbrcv2          ncb <>
  85.  
  86.  
  87. MAX_DG          equ 512
  88. rcv_buffer1     db MAX_DG dup(?)
  89. rcv_buffer2     db MAX_DG dup(?)
  90.  
  91.     public    as_send_pkt
  92. ; The Asynchronous Transmit Packet routine.
  93. ; Enter with es:di -> i/o control block, ds:si -> packet, cx = packet length,
  94. ;   interrupts possibly enabled.
  95. ; Exit with nc if ok, or else cy if error, dh set to error number.
  96. ;   es:di and interrupt enable flag preserved on exit.
  97. as_send_pkt:
  98.     ret
  99.  
  100.     public    drop_pkt
  101. ; Drop a packet from the queue.
  102. ; Enter with es:di -> iocb.
  103. drop_pkt:
  104.     assume    ds:nothing
  105.     ret
  106.  
  107.     public    xmit
  108. ; Process a transmit interrupt with the least possible latency to achieve
  109. ;   back-to-back packet transmissions.
  110. ; May only use ax and dx.
  111. xmit:
  112.     assume    ds:nothing
  113.     ret
  114.  
  115.  
  116.     public    send_pkt
  117. send_pkt:
  118.         assume ds: nothing
  119. ;enter with ds:si -> packet, cx = packet length.
  120. ;exit with nc if ok, or else cy if error, dh set to error number.
  121.         push    es
  122.         push    bx
  123.         push    ds
  124.  
  125.         push    cs
  126.         pop     es
  127.         mov     bx,offset cs:nbsend
  128.  
  129.         mov     cs:[bx].ncb_buffer.offs,si
  130.         mov     ax,ds
  131.         mov     cs:[bx].ncb_buffer.segm,ds
  132.         mov     cs:[bx].ncb_length,cx
  133.  
  134.         push    bx
  135.         lea     di,cs:nbsend.ncb_callname
  136.         mov     dh,ds:[si+16]
  137.         mov     dl,ds:[si+17]
  138.         mov     bh,ds:[si+18]
  139.         mov     bl,ds:[si+19]
  140.         push    cs
  141.         pop     ds
  142.         call    ip_to_nbname
  143.         pop     bx
  144.  
  145.         int     5ch
  146.  
  147.         cmp     al,0
  148.         jz      send_ok
  149.         add     ax,32
  150.         call    tty
  151.         mov     al,'S'
  152.         call    tty
  153.         stc
  154.         jmp     send_done
  155. send_ok:
  156.         mov     al,'s'
  157.         call    tty
  158.         clc
  159. send_done:
  160.         pop     ds
  161.         pop     bx
  162.         pop     es
  163.         ret
  164.  
  165.  
  166.  
  167.         public  get_address
  168. get_address:
  169. ;get the address of the interface.
  170. ;enter with es:di -> place to get the address, cx = size of address buffer.
  171. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  172.         clc
  173.         ret
  174.  
  175.  
  176.     public    set_address
  177. set_address:
  178. ;enter with ds:si -> Ethernet address, CX = length of address.
  179. ;exit with nc if okay, or cy, dh=error if any errors.
  180.     assume    ds:nothing
  181.     ret
  182.  
  183.  
  184. rcv_mode_3:
  185. ;receive mode 3 is the only one we support, so we don't have to do anything.
  186.     ret
  187.  
  188.  
  189.     public    set_multicast_list
  190. set_multicast_list:
  191. ;enter with ds:si ->list of multicast addresses, cx = number of addresses.
  192. ;return nc if we set all of them, or cy,dh=error if we didn't.
  193.     mov    dh,NO_MULTICAST
  194.     stc
  195.     ret
  196.  
  197.  
  198.     public    terminate
  199. terminate:
  200.     ret
  201.  
  202.         public  reset_interface
  203. reset_interface:
  204. ;reset the interface.
  205.         ret
  206.  
  207.  
  208. ;called when we want to determine what to do with a received packet.
  209. ;enter with cx = packet length, es:di -> packet type, dl = packet class.
  210.         extrn   recv_find: near
  211.  
  212. ;called after we have copied the packet into the buffer.
  213. ;enter with ds:si ->the packet, cx = length of the packet.
  214.         extrn   recv_copy: near
  215.  
  216.         extrn   count_in_err: near
  217.         extrn   count_out_err: near
  218.         extrn   dwordout: near
  219.         extrn   error: near
  220.  
  221.         public  recv
  222. recv:
  223. ;called from the recv isr.  All registers have been saved, and ds=cs.
  224. ;Upon exit, the interrupt will be acknowledged.
  225.         assume  ds:code
  226.         ret
  227.  
  228.         public nbint  ; MAP
  229. nbint   proc far
  230.         push ds
  231.         push cs
  232.         pop  ds
  233.         mov     al,'r'
  234.         call    tty
  235.         mov  al,[bx].ncb_retcode
  236.         cmp  al,0               ; ok
  237.         jnz  bad_nbint
  238.         push bx
  239.         mov  cx,[bx].ncb_length
  240.         mov  di,0
  241.     mov  dl,cs:driver_class
  242.         call recv_find
  243.         pop  bx
  244.         mov  ax,es
  245.         or   ax,di
  246.         je   nbint_done
  247.  
  248. ;                   cx, di already set
  249.         mov     si,[bx].ncb_buffer.offs
  250.         rep     movsb
  251.         call    recv_copy
  252.  
  253.         mov     [bx].ncb_length,MAX_DG  ; reestablish dg-length
  254.  
  255.         push    ds
  256.         pop     es
  257.         int 5ch
  258.         cmp     al,0ffh
  259.         jz      nbint_pending_ok1
  260.         mov     al,'?'
  261.         call    tty
  262.         cmp     al,00h
  263.         jz      nbint_pending_ok1
  264.         add     ax,32
  265.         call    tty
  266.         mov     al,'.'
  267.         call    tty
  268.  
  269. nbint_pending_ok1:
  270.         jmp     short nbint_done
  271.  
  272. bad_nbint:
  273.         cmp     ax,17h          ; name deleted
  274.         add     ax,32
  275.         call    tty
  276.         mov     al,'R'
  277.         call    tty
  278.  
  279. nbint_done:
  280.         pop ds
  281.         iret
  282. nbint   endp
  283.  
  284.         public  nb_stop
  285. nb_stop:
  286.         ;                   unregister name
  287.         push    cs
  288.         pop     es
  289.         lea      bx,nbrcv1
  290.         mov     [bx].ncb_command,NCB_DELNAME
  291. ;        mov     al,lana_num
  292. ;        mov     [bx].ncb_lana_num,al
  293.         int     5ch
  294.         cmp     al,0
  295.         jz      good_delete
  296.         add     ax,32
  297.         call    tty
  298.         mov     al,'I'
  299.         call    tty
  300. good_delete:
  301.         ret
  302.  
  303.  
  304.  
  305. tty:
  306.         push    bx
  307.         mov     ah,14
  308.         int     10h
  309.         pop     bx
  310.         ret
  311.  
  312. ip_to_nbname:
  313.         ;      call with es:di = *ncb_name
  314.         ;            bx and dx = ip_address
  315.  
  316.         mov     cx,5
  317.         mov     si,offset prefix
  318.         rep     movsb
  319.  
  320.         mov     [di],bx
  321.         mov     [di+2],dx
  322.         ret
  323.  
  324.     public    recv_exiting
  325. recv_exiting:
  326. ;called from the recv isr after interrupts have been acknowledged.
  327. ;Only ds and ax have been saved.
  328.     assume    ds:nothing
  329.     ret
  330.  
  331.  
  332. ;any code after this will not be kept after initialization.
  333.         public end_resident ; MAP
  334. end_resident    label   byte
  335.  
  336.  
  337.         public  usage_msg
  338. usage_msg       db      "usage: nb [-n] [-d] [-w] <packet_int_no> <ip.ad.dr.ess> [receive queue size]",CR,LF,'$'
  339.  
  340.         public  copyright_msg
  341. copyright_msg   db      "Packet driver for a netbios device, version ",'0'+majver,".",'0'+version,CR,LF
  342.                 db      "Portions Copyright 1990, Michael Haberler",CR,LF,'$'
  343.  
  344. ip_adress_name  db      "IP Adress ",'$'
  345. rq_size_name    db      "Receive Queue ",'$'
  346. bad_name_msg    db      " bad returncode from nb add_name",CR,LF,'$'
  347. bad_rcv_msg     db      " bad returncode from nb receive dg",CR,LF,'$'
  348. good_name_msg   db      " good returncode from nb add_name",CR,LF,'$'
  349. good_rcv_msg    db      " good returncode from nb receive dg",CR,LF,'$'
  350. temp_dw         dw      ?
  351.         extrn   set_recv_isr: near
  352.  
  353. ;enter with si -> argument string, di -> word to store.
  354. ;if there is no number, don't change the number.
  355.         extrn   get_number: near
  356.  
  357.         public  parse_args
  358. parse_args:
  359.         mov     di, offset temp_dw
  360.         mov     bx, offset ip_adress_name
  361.         call    get_number
  362.         mov     ax,temp_dw
  363.         mov     byte ptr ip_adress+3,al
  364.         inc     si
  365.         mov     di, offset temp_dw
  366.         mov     bx, offset ip_adress_name
  367.         call    get_number
  368.         mov     ax,temp_dw
  369.         mov     byte ptr ip_adress+2,al
  370.         inc     si
  371.         mov     di, offset temp_dw
  372.         mov     bx, offset ip_adress_name
  373.         call    get_number
  374.         mov     ax,temp_dw
  375.         mov     byte ptr ip_adress+1,al
  376.         inc     si
  377.         mov     di, offset temp_dw
  378.         mov     bx, offset ip_adress_name
  379.         call    get_number
  380.         mov     ax,temp_dw
  381.         mov     byte ptr ip_adress+0,al
  382.  
  383.         mov     di, offset rq_size
  384.         mov     bx, offset rq_size_name
  385.         call    get_number
  386.         ret
  387.  
  388.  
  389.  
  390.         public  etopen
  391. etopen:
  392.         pushf
  393.         cld
  394.  
  395. ;if all is okay,
  396. ;        mov     bx,offset nbsend
  397.         lea     bx,nbsend
  398.         mov     [bx].ncb_command,NCB_ADDNAME
  399.         mov     al,lana_num
  400.         mov     [bx].ncb_lana_num,al
  401.  
  402.         push    ds
  403.         push    cs
  404.         push    cs
  405.         pop     ds
  406.         pop     es
  407.  
  408.         push    bx
  409.         lea     di,nbsend.ncb_name
  410.         mov     bx,ip_adress
  411.         mov     dx,ip_adress+2
  412.         call    ip_to_nbname
  413.         pop     bx
  414.  
  415.         mov     cx,16
  416.         mov     di,offset nbrcv1.ncb_name
  417.         mov     si,offset nbsend.ncb_name
  418.         rep     movsb
  419.         mov     cx,16
  420.         mov     di,offset nbrcv2.ncb_name
  421.         mov     si,offset nbsend.ncb_name
  422.         rep     movsb
  423.  
  424.         int     5ch     ; add_name, -> returns rc in al
  425.         cmp     al,0
  426.         jz      good_name
  427.         mov     dx,0
  428.         mov     ah,0
  429.         call    dwordout
  430.         mov     dx,offset bad_name_msg
  431.         pop     ds
  432.         jmp     error
  433.  
  434. good_name:
  435. ;        mov     dx,offset good_name_msg
  436. ;        call    say
  437.  
  438.         mov     al,[bx].ncb_num
  439.         mov     local_ncb_num,al
  440.         mov     [bx].ncb_command,NCB_SDATAGRAM  ;set send command code
  441.  
  442.         ;       start receive operations
  443. ;        mov     bx,offset nbrcv1
  444.         lea     bx,nbrcv1
  445.         mov     al,NCB_RDATAGRAM+NCB_NOWAIT  ;set rcv command
  446.         mov     [bx].ncb_command,al
  447.  
  448.         mov     al,local_ncb_num
  449.         mov     [bx].ncb_num,al
  450.  
  451.         mov     ax,MAX_DG
  452.         mov     [bx].ncb_length,ax
  453.  
  454.         mov     ax,ds
  455.         mov     [bx].ncb_buffer.segm,ax
  456.         mov     [bx].ncb_buffer.offs,offset rcv_buffer1
  457.  
  458.         mov     [bx].ncb_post.segm,ax
  459.         mov     [bx].ncb_post.offs,offset nbint
  460.  
  461.         mov     al,lana_num
  462.         mov     [bx].ncb_lana_num,al
  463.         int     5ch
  464.  
  465.         cmp     al,0ffh
  466.         jz      pending_ok1
  467.         cmp     al,00h
  468.         jnz     bad_init
  469.  
  470. pending_ok1:
  471.         mov     dx,offset good_rcv_msg
  472.         call    say
  473.  
  474.         mov     dx,offset end_resident
  475.         pop     ds
  476.         popf
  477.         clc
  478.         ret
  479. ;if we got an error,
  480. bad_init:
  481.         mov     ah,0
  482.         mov     dx,0
  483.         call    dwordout
  484.         mov     dx,offset bad_rcv_msg
  485.         call    say
  486.         call    nb_stop
  487.         pop     ds
  488.         popf
  489.         stc
  490.         ret
  491.  
  492.     public    print_parameters
  493. print_parameters:
  494.     ret
  495.  
  496. say:
  497.         mov     ah,9
  498.         int     21h
  499.         ret
  500.  
  501.  
  502. code    ends
  503.  
  504.         end
  505.  
  506.